<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from './hooks'

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    name: "",
    status: 1,
    type: 0,
    sort: null,
    note: ""
  }),
  mapTypes: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const mapTypes = ref(props.mapTypes);
const { switchStyle } = usePublicHooks();

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="82px">
    <el-row :gutter="30">
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="地图名称" prop="name">
          <el-input v-model="newFormInline.name" clearable placeholder="请输入地图名称" />
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="状态" prop="status">
          <el-switch v-model="newFormInline.status" inline-prompt :active-value="1" :inactive-value="0" active-text="启用"
            inactive-text="停用" :style="switchStyle" />
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="类型" prop="type">
          <el-select v-model="newFormInline.type" placeholder="请选择适用地图" style="width:100%">
            <el-option v-for="item in mapTypes" :key="Number(item.Value)" :label="item.Name"
              :value="Number(item.Value)" />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="排序" prop="sort">
          <el-input-number v-model="newFormInline.sort" controls-position="right" placeholder="请输入排序" />
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="备注" prop="note">
          <el-input v-model="newFormInline.note" clearable placeholder="请输入备注" type="textarea" />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
  margin-right: 16px;
}
</style>
